(** 
    Top-level interpreter for the Gnarly programming language. Handles I/O and interactive interpretation and mediates between parser and interpreter.
    @author mmvitousek
*)

open Primitives
open Interface
open Printing
exception SyntaxError

(** Current overall Gnarly version number *)
let version = "0.7.3"
let pervasives_location = "pervasives.nr"

(** The initial execution environment *)
let global_env = setup_global_env
(** The initial type environment *)
and global_tenv = setup_global_tenv
			
(** 
    Entry point for execution of the Gnarly interpreter. May be supplied with command line arguments of files to be typechecked and executed 
    on program initialization
*)
let  _ =
	print_fix ("Gnarly " ^ version ^ "\n");
	pervasive_mode := true;
	(try (
		interpret_file pervasives_location global_env global_tenv;
		pervasive_mode := false;
	) with Sys_error(err) -> (
		pervasive_mode := false;
		print_fix ("Could not open Pervasives (" ^ err ^ ")\n");
	));
	for i = 1 to Array.length Sys.argv - 1 do
		match Sys.argv.(i) with
		      _ as file -> (
			      try (
				       interpret_file file global_env global_tenv
			       ) with Sys_error(err) -> print_fix (err ^ "\n")
		      )
	done;
	interpret_repl global_env global_tenv
